
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets" template="/template/main.xhtml">

	<ui:define name="body">
		<h:panelGroup id="grupo">
			<h:form prependId="false">
	
				<p:toolbar>
					<p:toolbarGroup align="left">
						<p:commandButton value="#{messages['button.save']}" action="#{tabelaPrecoEditMB.insert}"
							rendered="#{!tabelaPrecoEditMB.updateMode}" ajax="false" />
						<p:commandButton value="#{messages['button.save']}" action="#{tabelaPrecoEditMB.update}"
							rendered="#{tabelaPrecoEditMB.updateMode}" ajax="false" />
						<p:commandButton value="#{messages['button.delete']}" onclick="confirmation.show()"
							rendered="#{tabelaPrecoEditMB.updateMode}" type="button" immediate="true" ajax="false" />
						<p:confirmDialog message="#{messages['label.confirm.delete']}" showEffect="bounce" hideEffect="explode"
							header="#{messages['label.dialog.delete']}" severity="alert" widgetVar="confirmation">
							<h:commandButton value="#{messages['button.dialog.yes']}" action="#{tabelaPrecoEditMB.delete}" immediate="true"
								ajax="false" />
							<h:commandButton value="#{messages['button.dialog.no']}" onclick="confirmation.hide()" type="button" />
						</p:confirmDialog>
					</p:toolbarGroup>
				</p:toolbar>
	
				<br />
	
				<p:fieldset legend="#{messages['tabelaPreco.label']}" toggleable="true" toggleSpeed="500">
					<h:panelGrid id="fields" columns="3">
						
						<h:outputLabel value="#{messages['tabelaPreco.label.id']}: " for="id" styleClass="text-input" />
						<h:outputText id="id" value="#{tabelaPrecoEditMB.bean.id}" />
						<p:message for="id" />
						
						<h:outputLabel value="#{messages['tabelaPreco.label.descricao']}: " for="descricao" styleClass="text-input" />
						<h:inputText id="descricao"  maxlength="100" size="80" required="true" requiredMessage="#{messages['mensagem_geral.campoObrigatorio']}" value="#{tabelaPrecoEditMB.bean.descricao}"
							title="#{messages['tabelaPreco.alt.descricao']}" />
						<p:message for="descricao" />
						
					</h:panelGrid>
				</p:fieldset>
			</h:form>
			
			<p:spacer height="20" width="20"/>  
	
			<h:form enctype="multipart/form-data">
				<p:fieldset legend="#{messages['itemTabelaPreco.list.table.title']}" toggleable="true" toggleSpeed="500">
	
					<h:panelGrid id="fields2" columns="3">
	
						<h:outputLabel value="#{messages['tabelaPreco.label.importar']}: "  for="file"  styleClass="text-input" />
						<p:fileUpload id="file" fileUploadListener="#{tabelaPrecoEditMB.handleFileUpload}" mode="advanced" 
							dragDropSupport="true"
	                  		update="fields2" sizeLimit="100000" fileLimit="3" allowTypes="/(\.|\/)(csv|txt)$/" auto="false" >
	                  	</p:fileUpload>
	                  	<h:message for="file" />
	
						<h:outputLabel value="#{messages['tabelaPreco.label.codigoItem']}: " for="codigoItem" styleClass="text-input" />
						<h:inputText id="codigoItem"  maxlength="100" required="true" requiredMessage="#{messages['mensagem_geral.campoObrigatorio']}" value="#{tabelaPrecoEditMB.codigoItem}"
							title="#{messages['tabelaPreco.alt.codigoItem']}" />
						<p:message for="codigoItem" />
	
						<h:outputLabel value="#{messages['tabelaPreco.label.descricaoItem']}: " for="descricaoItem" styleClass="text-input" />
						<h:inputTextarea style="width:820"  id="descricaoItem"  maxlength="1500" required="true" requiredMessage="#{messages['mensagem_geral.campoObrigatorio']}" value="#{tabelaPrecoEditMB.descricaoItem}"
							title="#{messages['tabelaPreco.alt.descricaoItem']}" />
						<p:message for="descricaoItem" />
	
						<h:outputLabel value="#{messages['tabelaPreco.label.unidadeMedidaItem']}:" for="unidadeMedidaItem" styleClass="text-input" />
						<h:selectOneMenu value="#{tabelaPrecoEditMB.unidadeMedidaItem}" id="unidadeMedidaItem" style="width: 270px;"
							title="#{messages['tabelaPreco.label.unidadeMedidaItem']}" required="true"
							requiredMessage="#{messages['mensagem_geral.campoObrigatorio']}">
							<f:selectItem itemLabel="Selecione" itemValue="" />	
	 						<f:selectItems value="#{tabelaPrecoEditMB.unidadeMedidas}"></f:selectItems>
						</h:selectOneMenu>
						<p:message for="unidadeMedidaItem"/>
	
						<h:outputLabel value="#{messages['tabelaPreco.label.valorItem']}: " for="valorItem" styleClass="text-input" />
						<h:inputText id="valorItem"  maxlength="100" required="true" requiredMessage="#{messages['mensagem_geral.campoObrigatorio']}" value="#{tabelaPrecoEditMB.valorItem}"
							title="#{messages['tabelaPreco.alt.valorItem']}" />
						<p:message for="valorItem" />
	
						<f:facet name="footer">
					    	<h:panelGroup>
	
								<h:commandButton value="#{messages['button.add']}"  action="#{tabelaPrecoEditMB.adicionarItem()}" ajax="true" >
					    			<f:ajax execute="fields2" render="fields2" />
					    	   	</h:commandButton>
								<p:message for="list"/>
	
								<p:dataTable id="list" var="bean" value="#{tabelaPrecoEditMB.bean.listaItemTabelaPrecos}" rowIndexVar="rowIndex" >
									<f:facet name="header">#{messages['itemTabelaPreco.list.table.title']}</f:facet>
	
									<p:column style="width:5%;" sortBy="#{rowIndex}">
										<f:facet name="header">#{messages['button.remove']}</f:facet>
										<h:commandButton value="#{messages['button.remove']}" action="#{tabelaPrecoEditMB.removerItem()}" ajax="true" >
							    			<f:ajax execute="list" render="list" immediate="true"/>
											<f:setPropertyActionListener target="#{tabelaPrecoEditMB.posicao}" value="#{rowIndex}" />
										</h:commandButton>
									</p:column>
	
									<p:column sortBy="#{bean.codigo}">
										<f:facet name="header">#{messages['tabelaPreco.label.codigoItem']}</f:facet>
											<h:outputText value="#{bean.codigo}" />
									</p:column>
	
									<p:column sortBy="#{bean.descricao}" style="font-size:11">
										<f:facet name="header">#{messages['tabelaPreco.label.descricaoItem']}</f:facet>
											<h:outputText value="#{bean.descricao}" />
									</p:column>
				
									<p:column sortBy="#{bean.unidade.descricao}">
										<f:facet name="header">#{messages['tabelaPreco.label.unidadeMedidaItem']}</f:facet>
											<h:outputText value="#{bean.unidade.descricao}" />
									</p:column>
	
									<p:column sortBy="#{bean.valorUnitario}">
										<f:facet name="header">#{messages['tabelaPreco.label.valorItem']}</f:facet>
											<h:outputText value="#{bean.valorUnitario}" />
									</p:column>
	
								</p:dataTable>
					  		</h:panelGroup>
					  	</f:facet>
					</h:panelGrid>
				</p:fieldset>
			</h:form>
		</h:panelGroup>
	</ui:define>
</ui:composition>